﻿using System;
using System.Net;
using SalaryChannel.SCPublicInforService;
using SalaryChannel.SCUserService;
using SalaryChannel.SCQueryService;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Net.Browser;
using SalaryChannel.ViewService;
namespace SalaryChannel
{
    public static class ServiceInstance
    {

        public static readonly string UserName = "yangch_ts";
        public static readonly string Password = "sc.yc.cobs";

        private static UserServiceClient _userClient = null;
        private static OperationContext _userPC = null;
        public static UserServiceClient UserClient
        {
            get
            {
                if (_userClient == null)
                {
                    _userClient = new UserServiceClient();

                    OperationContext.Current = new OperationContext((IContextChannel)_userClient.InnerChannel);
                    MessageHeader header = MessageHeader.CreateHeader("uafcztga", "", UserName);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);
                    header = MessageHeader.CreateHeader("xufasft", "", Password);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);
                    _userPC = OperationContext.Current;
                }
                else
                {
                    OperationContext.Current = _userPC;
                }
                return ServiceInstance._userClient;
            }
        }

        private static PublicInforClient _publicInforClient = null;
        private static OperationContext _publicPC = null;
        public static PublicInforClient PublicInforClient
        {
            get
            {
                if (_publicInforClient == null)
                {
                    try
                    {
                        _publicInforClient = new PublicInforClient();
                        OperationContext.Current = new OperationContext((IContextChannel)_publicInforClient.InnerChannel);
                        MessageHeader header = MessageHeader.CreateHeader("uafcztga", "", UserName);
                        OperationContext.Current.OutgoingMessageHeaders.Add(header);
                        header = MessageHeader.CreateHeader("xufasft", "", Password);
                        OperationContext.Current.OutgoingMessageHeaders.Add(header);
                        _publicPC = OperationContext.Current;
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    OperationContext.Current = _publicPC;
                }
                return ServiceInstance._publicInforClient;
            }
        }

        private static QueryServiceClient _queryClient = null;
        private static OperationContext _queryPC = null;
        public static QueryServiceClient QueryClient
        {
            get
            {
                if (_queryClient == null)
                {
                    _queryClient = new QueryServiceClient();

                    OperationContext.Current = new OperationContext((IContextChannel)_queryClient.InnerChannel);
                    MessageHeader header = MessageHeader.CreateHeader("uafcztga", "", UserName);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);
                    header = MessageHeader.CreateHeader("xufasft", "", Password);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);

                    bool registerResult = WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
                    bool httpsResult = WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);


                    _queryPC = OperationContext.Current;
                }
                else
                {
                    OperationContext.Current = _queryPC;
                }
                return ServiceInstance._queryClient;
            }
        }

        private static AdviseService.AdviseServiceClient _adviseClient = null;
        private static OperationContext _advisePC = null;
        public static AdviseService.AdviseServiceClient AdviseClient
        {
            get
            {
                if (_adviseClient == null)
                {
                    _adviseClient = new SalaryChannel.AdviseService.AdviseServiceClient();
                    OperationContext.Current = new OperationContext((IContextChannel)_adviseClient.InnerChannel);
                    MessageHeader header = MessageHeader.CreateHeader("uafcztga", "", UserName);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);
                    header = MessageHeader.CreateHeader("xufasft", "", Password);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);

                    _advisePC = OperationContext.Current;
                }
                else
                {
                    OperationContext.Current = _advisePC;
                }
                return _adviseClient;
            }
        }

        private static ViewService.ChannelViewServiceClient _viewService = null;
        private static OperationContext _veiwPC = null;
        public static ViewService.ChannelViewServiceClient ViewService
        {
            get
            {
                if (_viewService == null)
                {
                    _viewService = new ChannelViewServiceClient();
                    OperationContext.Current = new OperationContext((IContextChannel)_viewService.InnerChannel);
                    MessageHeader header = MessageHeader.CreateHeader("uafcztga", "", UserName);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);
                    header = MessageHeader.CreateHeader("xufasft", "", Password);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);

                    _veiwPC = OperationContext.Current;
                }
                else
                {
                    OperationContext.Current = _veiwPC;
                }
                return _viewService;
            }
        }
        //*/

        private static TaskWebService.TaskServiceClient _taskService = null;
        private static OperationContext _taskPC = null;
        public static TaskWebService.TaskServiceClient TaskService
        {
            get
            {
                if (_taskService == null)
                {
                    _taskService = new SalaryChannel.TaskWebService.TaskServiceClient();
                    OperationContext.Current = new OperationContext((IContextChannel)_taskService.InnerChannel);
                    MessageHeader header = MessageHeader.CreateHeader("uafcztga", "", UserName);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);
                    header = MessageHeader.CreateHeader("xufasft", "", Password);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);

                    _taskPC = OperationContext.Current;
                }
                else
                {
                    OperationContext.Current = _taskPC;
                }
                return ServiceInstance._taskService;
            }
        }

        private static InforWebService.InforServiceClient _inforService = null;
        private static OperationContext _inforPC = null;
        public static InforWebService.InforServiceClient InforService
        {
            get
            {
                if (_inforService == null)
                {
                    _inforService = new SalaryChannel.InforWebService.InforServiceClient();
                    OperationContext.Current = new OperationContext((IContextChannel)_inforService.InnerChannel);
                    MessageHeader header = MessageHeader.CreateHeader("uafcztga", "", UserName);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);
                    header = MessageHeader.CreateHeader("xufasft", "", Password);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);

                    _inforPC = OperationContext.Current;
                }
                else
                {
                    OperationContext.Current = _inforPC;
                }
                return _inforService;
            }
        }

       
        private static SupportService.SupportServiceClient _supportSerivce = null;

        private static OperationContext _supporttPC = null;
        public static SupportService.SupportServiceClient SupportSerivce
        {
            get
            {
                if (_supportSerivce == null)
                {
                    _supportSerivce = new SalaryChannel.SupportService.SupportServiceClient();
                    OperationContext.Current = new OperationContext((IContextChannel)_supportSerivce.InnerChannel);
                    MessageHeader header = MessageHeader.CreateHeader("uafcztga", "", UserName);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);
                    header = MessageHeader.CreateHeader("xufasft", "", Password);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);

                    _supporttPC = OperationContext.Current;
                }
                else
                {
                    OperationContext.Current = _supporttPC;
                }
                return _supportSerivce;
            }
        }
    }
}
